let handler = {
  37(arr, food) {
    change(arr, food, -1);
  },
  38(arr, food) {
    change(arr, food, -16);
  },
  39(arr, food) {
    change(arr, food, 1);
  },
  40(arr, food) {
    change(arr, food, 16);
  },
};
function change(arr, food, num) {
  arr.unshift(arr[0] + num);
  if (arr.includes(food[0])) {
    food[0] = random(arr);
  } else {
    arr.pop();
  }
}
//添加两个随机0
function random(arr) {
  let num = ~~(Math.random() * 16 * 16);
  while (arr.includes(num)) {
    num = ~~(Math.random() * 16 * 16);
  }
  return num;
}
function throttle(fn, wait = 300) {
  let lastTime = 0;
  return function (...args) {
    let now = +new Date();
    if (now - lastTime > wait) {
      lastTime = now;
      fn.apply(this, args);
    }
  };
}
export { throttle };
export default handler;
